package com.niiwoo.civet.trade.service.local.notify.impl;

import com.niiwoo.civet.trade.dto.ProjectNotifyDTO;
import com.niiwoo.civet.trade.enums.NotifyTypeEnum;
import com.niiwoo.civet.user.dto.request.AppButtonDTO;
import com.niiwoo.civet.user.dto.request.JPushExtDTO;
import com.niiwoo.civet.user.dto.request.UserLetterRequestDTO;
import com.niiwoo.civet.user.enums.JPushEnum;
import com.niiwoo.civet.user.enums.MessageTemplateKeyEnum;
import com.niiwoo.civet.user.enums.UserLetterTypeEnum;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class ProjectFlowMiscarryManualFailedNotifier extends AbstractBorrowNotifier<ProjectNotifyDTO> {

    @Override
    protected List<? extends UserNotifyInfo> getUserNotifyInfoList(ProjectNotifyDTO t) {
        BorrowUserNotifyInfo info = new BorrowUserNotifyInfo();
        info.setUserId(t.getBorrowUserId());
        info.setProjectId(t.getProjectId());
        info.setProjectTitle(t.getTitle());
        info.setMobileNo(privacyMasks.decryptPrivacy(t.getBorrowMobile()));
        info.setPushContent(t.getPushContent());
        info.setProjectType(t.getType());
        info.setProjectFrom(t.getFromSource());
        return Collections.singletonList(info);
    }

    // 借款标审核不通过
    // JS005 借款人
    // 通知 + 极光推送：抱歉，借款发布失败 / 您好，您的借款项目【项目名称】未能通过审核，暂时无法借款，原因为：{后台维护}。如有疑问可咨询钱小二。"
    @Override
    protected UserLetterRequestDTO getUserLetterRequestDTO(UserNotifyInfo info) {
        BorrowUserNotifyInfo p = (BorrowUserNotifyInfo) info;
        UserLetterRequestDTO letterRequest = new UserLetterRequestDTO();
        // 通知
        List<Object> letterParams = Arrays.asList(p.getProjectId(), p.getProjectTitle(), StringUtils.defaultIfBlank(p.getPushContent(), "信审手动流标"));
        letterRequest.setLetterTemplateEnum(MessageTemplateKeyEnum.LetterTemplateKeyEnum.PROJECT_FLOW_MISCARRY_MANUAL_FAILED);
        letterRequest.setLetterTemplateParamList(letterParams);
        // 按钮
        AppButtonDTO buttonDTO = new AppButtonDTO();
        buttonDTO.setButtonType(AppButtonDTO.ButtonTypeEnum.MONEY_2);
        buttonDTO.setLabel(AppButtonDTO.ButtonTypeEnum.MONEY_2.getDesc());
        letterRequest.setLetterButtonList(Collections.singletonList(buttonDTO));
        // 极光推送
        List<Object> pushParams = Arrays.asList(p.getProjectTitle(), StringUtils.defaultIfBlank(p.getPushContent(), "信审手动流标"));
        letterRequest.setJpushTemplateKeyEnum(MessageTemplateKeyEnum.JPushTemplateKeyEnum.PROJECT_FLOW_MISCARRY_MANUAL_FAILED);
        letterRequest.setJpushTemplateParamList(pushParams);
        letterRequest.setToUserId(p.getUserId());
        letterRequest.setProjectId(p.getProjectId());
        letterRequest.setUserLetterTypeEnum(UserLetterTypeEnum.LETTER_AND_JPUSH);
        JPushExtDTO jPushExtDTO = new JPushExtDTO();
        jPushExtDTO.setRedirectPageEnum(JPushEnum.RedirectPageEnum.NOTICE_LIST_PAGE);
        letterRequest.setJPushExt(jPushExtDTO);
        return letterRequest;
    }


    @Override
    protected NotifyTypeEnum getType() {
        return NotifyTypeEnum.JS005;
    }

}
